<?python
  layout_params['pageType'] = 'document details'
  from harava.rdf import *
?>
<html py:layout="'layout.kid'" xmlns:py="http://purl.org/kid/ns#">

<body>

<div py:match="item.get('id') == 'content'" id="content">

<h2>Document details</h2>

<form action="${rep.getCGIURL()}" method="GET">
<p>Source document: <a href="${doc.getURL()}">${doc.getTitle()}</a></p>
<p>Status: 
  <span py:if="doc.getSuccesful()" class="status ${doc.getWarnings() and 'warn' or 'succ'}"> Success, ${doc.getWarnings()} warnings </span>
  <span py:if="not doc.getSuccesful()" class='status crit'> Failed </span>
  <input py:if="rep.getCGIURL()" type="submit" name="submit" value="Refresh" />
</p>
<input type="hidden" name="config" value="${rep.getConfigName()}" />
<input type="hidden" name="source" value="${rep.getSourceName()}" />
<input type="hidden" name="type" value="${rep.getSourceType()}" />
<input type="hidden" name="url" value="${doc.getURL()}" />
</form>

<h3>Problems</h3>

<table>
<thead>
<tr>
  <th class="phase">Phase</th>
  <th class="type">Type</th>
  <th class="details">Details</th>
</tr>
</thead>
<tbody>

<tr py:for="msg in rep.getDocumentProblems(doc.getURL())">
  <td class="phase ${msg['level'].lower()}">${msg['phase']}</td>
  <td class="type ${msg['level'].lower()}">${msg['type']}</td>
  <td class="details ${msg['level'].lower()}">${msg['details']}</td>
</tr>
</tbody>
</table>

<h3>Collected metadata</h3>

<table>
<thead>
<tr>
  <th>Field name</th>
  <th>Field ID</th>
  <th>Value</th>
</tr>
</thead>
<tbody>

<?python graph = doc.getMetadataGraph() ?>

<tr py:for="name, id, prop in rep.getMetadataFields(doc)">
  <td>$name</td>
  <td>$id</td>
  <td>
    <div py:for="val in doc.getMetadata(prop)">
      <span py:strip="True" py:if="isinstance(val, str)">$val</span>
      <span py:strip="True" py:if="isinstance(val, Literal)">$val<span py:if="val.language" class="language">@${val.language}</span></span>
      <span py:strip="True" py:if="isinstance(val, URIRef)"><a href="$val">$val</a></span>
      <span py:strip="True" py:if="isinstance(val, BNode)">
      	<span py:strip="True" py:if="graph.value(val, RDF.type, None) == DCTERMS.W3CDTF">"${graph.value(val, RDF.value, None)}" <span class="insttype"> a dcterms:W3CDTF</span></span>
      	<span py:strip="True" py:if="graph.value(val, RDF.type, None) == DCTERMS.IMT">"${graph.value(val, RDF.value, None)}" <span class="insttype"> a dcterms:IMT</span></span>
      	<span py:strip="True" py:if="graph.value(val, RDF.type, None) == DCTERMS.RFC3066">"${graph.value(val, RDF.value, None)}" <span class="insttype"> a dcterms:RFC3066</span></span>
      	<span py:strip="True" py:if="graph.value(val, RDF.type, None) == FOAF.Organization">"${graph.value(val, FOAF.name, None)}" <span class="insttype"> a foaf:Organization</span></span>
      	<span py:strip="True" py:if="graph.value(val, RDF.type, None) == FOAF.Person">"${graph.value(val, FOAF.name, None)}" <span class="insttype"> a foaf:Person</span></span>
      	<span py:strip="True" py:if="graph.value(val, RDF.type, None) == FOAF.Agent">"${graph.value(val, FOAF.name, None)}" <span class="insttype"> a foaf:Agent</span></span>
      	<span py:strip="True" py:if="graph.value(val, RDF.type, None) == FOAF.Group">"${graph.value(val, FOAF.name, None)}" <span class="insttype"> a foaf:Group</span></span>
      	<span py:strip="True" py:if="graph.value(val, RDF.type, None) == VCARD.VCard">"${graph.value(val, VCARD['fn'], None)}" <span class="insttype"> a vcard:VCard</span></span>
      </span>
      <span py:strip="True" py:if="not isinstance(val, (str, Literal, URIRef, BNode))">$val (${type(val)})</span>
    </div>
  </td>
</tr>
</tbody>
</table>




</div>

</body>

</html>
